<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mother extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function saveEmailDB($ip)
    {
        $email = $this->getParamString('email');
        if($this->valid_email($email) == 1)
        {
            return 202;
        }
        $id_shop = $this->db->query('SELECT id FROM shop WHERE ip = "'.$ip.'"')->row_object()->id;
        $check = $this->m_db->where(array('id_shop' => intval($id_shop), 'email' => strtolower($email)))->count('log_mail');
        if($check == 0)
        {
            ini_set('mongo.native_long', 1);
            $now = date("Y-m-d H:i:s", time());
            $nr = date('YmdHis');
            $cd__ = new MongoInt64($nr);
            $arr = array(
                        'email' => strtolower($email), 
                        'id_shop' => $id_shop,
                        'time_access'           => date('Y-m-d H:i:s'),
                        'show_time'             => date('d-m-Y'),
                        'show_full_time'        => date('H:i:s d-m-Y'),
                        'time_vs'               => $cd__,
                );
            $this->m_db->insert('log_mail', $arr);
        }
        return 200;
    }
    
    public function saveFacebookDB($ip)
    {
        $email = $this->getParamString('email');
        $url = $this->getParamString('url');
        $fullname = $this->getParamString('fullname');
        if($this->valid_email($email) == 1)
        {
            return 202;
        }
        $id_shop = $this->db->query('SELECT id FROM shop WHERE ip = "'.$ip.'"')->row_object()->id;
        $check = $this->m_db->where(array('id_shop' => intval($id_shop), 'email' => strtolower($email)))->count('log_facebook');
        if($check == 0)
        {
            ini_set('mongo.native_long', 1);
            $now = date("Y-m-d H:i:s", time());
            $nr = date('YmdHis');
            $cd__ = new MongoInt64($nr);
            $arr = array(
                        'email'                 => strtolower($email),
                        'url'                   => strtolower($url),
                        'fullname'              => strtolower($fullname), 
                        'id_shop'               => $id_shop,
                        'time_access'           => date('Y-m-d H:i:s'),
                        'show_time'             => date('d-m-Y'),
                        'show_full_time'        => date('H:i:s d-m-Y'),
                        'time_vs'               => $cd__,
                );
            $this->m_db->insert('log_facebook', $arr);
        }
        return 200;
    }
    
}